package com.qq.BFMRSE.util;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.commons.codec.binary.Hex;

public class MD5Util {
	/**
	 * get the digest of a string
	 * @param str
	 * @return
	 */
	public static String encodeMD5(String str)
	{
		MessageDigest md5=null;
		String result=null;
		try {
			md5=MessageDigest.getInstance("MD5");
			byte []temp=md5.digest(str.getBytes("utf-8"));
			result=Hex.encodeHexString(temp);
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}

}
